// $ANTLR 3.2 Sep 23, 2009 12:02:23 /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g 2012-10-16 23:47:18

	package calc;
	import java.util.Map;
	import java.util.HashMap;
	import java.util.Random;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

public class GrammarEvaluator extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "NEGATION", "IDENT", "INTEGER", "LETTER", "DIGIT", "WS", "':='", "';'", "'('", "')'", "'+'", "'-'", "'*'", "'/'", "'mod'"
    };
    public static final int INTEGER=6;
    public static final int LETTER=7;
    public static final int T__12=12;
    public static final int IDENT=5;
    public static final int T__17=17;
    public static final int NEGATION=4;
    public static final int WS=9;
    public static final int EOF=-1;
    public static final int T__13=13;
    public static final int T__16=16;
    public static final int T__10=10;
    public static final int DIGIT=8;
    public static final int T__14=14;
    public static final int T__11=11;
    public static final int T__18=18;
    public static final int T__15=15;

    // delegates
    // delegators


        public GrammarEvaluator(TreeNodeStream input) {
            this(input, new RecognizerSharedState());
        }
        public GrammarEvaluator(TreeNodeStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        

    public String[] getTokenNames() { return GrammarEvaluator.tokenNames; }
    public String getGrammarFileName() { return "/Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g"; }


    	public Map<String, Integer> variables = new HashMap<String, Integer>();



    // $ANTLR start "evaluator"
    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:20:1: evaluator returns [int result] : e= expression EOF ;
    public final int evaluator() throws RecognitionException {
        int result = 0;

        int e = 0;


        try {
            // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:21:2: (e= expression EOF )
            // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:21:4: e= expression EOF
            {
            pushFollow(FOLLOW_expression_in_evaluator62);
            e=expression();

            state._fsp--;

            match(input,EOF,FOLLOW_EOF_in_evaluator64); 
            result = e;

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return result;
    }
    // $ANTLR end "evaluator"


    // $ANTLR start "expression"
    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:24:1: expression returns [int result] : ( ^( '+' op1= expression op2= expression ) | ^( '-' op1= expression op2= expression ) | ^( '*' op1= expression op2= expression ) | ^( '/' op1= expression op2= expression ) | ^( 'mod' op1= expression op2= expression ) | ^( NEGATION e= expression ) | IDENT | INTEGER );
    public final int expression() throws RecognitionException {
        int result = 0;

        CommonTree IDENT1=null;
        CommonTree INTEGER2=null;
        int op1 = 0;

        int op2 = 0;

        int e = 0;


        try {
            // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:25:2: ( ^( '+' op1= expression op2= expression ) | ^( '-' op1= expression op2= expression ) | ^( '*' op1= expression op2= expression ) | ^( '/' op1= expression op2= expression ) | ^( 'mod' op1= expression op2= expression ) | ^( NEGATION e= expression ) | IDENT | INTEGER )
            int alt1=8;
            switch ( input.LA(1) ) {
            case 14:
                {
                alt1=1;
                }
                break;
            case 15:
                {
                alt1=2;
                }
                break;
            case 16:
                {
                alt1=3;
                }
                break;
            case 17:
                {
                alt1=4;
                }
                break;
            case 18:
                {
                alt1=5;
                }
                break;
            case NEGATION:
                {
                alt1=6;
                }
                break;
            case IDENT:
                {
                alt1=7;
                }
                break;
            case INTEGER:
                {
                alt1=8;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 1, 0, input);

                throw nvae;
            }

            switch (alt1) {
                case 1 :
                    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:25:4: ^( '+' op1= expression op2= expression )
                    {
                    match(input,14,FOLLOW_14_in_expression82); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expression_in_expression86);
                    op1=expression();

                    state._fsp--;

                    pushFollow(FOLLOW_expression_in_expression90);
                    op2=expression();

                    state._fsp--;


                    match(input, Token.UP, null); 
                    result = op1 + op2;

                    }
                    break;
                case 2 :
                    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:26:4: ^( '-' op1= expression op2= expression )
                    {
                    match(input,15,FOLLOW_15_in_expression99); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expression_in_expression103);
                    op1=expression();

                    state._fsp--;

                    pushFollow(FOLLOW_expression_in_expression107);
                    op2=expression();

                    state._fsp--;


                    match(input, Token.UP, null); 
                    result = op1 - op2;

                    }
                    break;
                case 3 :
                    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:27:4: ^( '*' op1= expression op2= expression )
                    {
                    match(input,16,FOLLOW_16_in_expression116); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expression_in_expression120);
                    op1=expression();

                    state._fsp--;

                    pushFollow(FOLLOW_expression_in_expression124);
                    op2=expression();

                    state._fsp--;


                    match(input, Token.UP, null); 
                    result = op1 * op2;

                    }
                    break;
                case 4 :
                    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:28:4: ^( '/' op1= expression op2= expression )
                    {
                    match(input,17,FOLLOW_17_in_expression133); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expression_in_expression137);
                    op1=expression();

                    state._fsp--;

                    pushFollow(FOLLOW_expression_in_expression141);
                    op2=expression();

                    state._fsp--;


                    match(input, Token.UP, null); 

                    				if(op2 == 0){
                    					result = 100*(op2 / op1);
                    				}else{
                    					result = 100*(op1 / op2);
                    				}
                    			

                    }
                    break;
                case 5 :
                    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:35:4: ^( 'mod' op1= expression op2= expression )
                    {
                    match(input,18,FOLLOW_18_in_expression149); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expression_in_expression153);
                    op1=expression();

                    state._fsp--;

                    pushFollow(FOLLOW_expression_in_expression157);
                    op2=expression();

                    state._fsp--;


                    match(input, Token.UP, null); 
                    result = op1 % op2;

                    }
                    break;
                case 6 :
                    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:36:4: ^( NEGATION e= expression )
                    {
                    match(input,NEGATION,FOLLOW_NEGATION_in_expression166); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expression_in_expression170);
                    e=expression();

                    state._fsp--;


                    match(input, Token.UP, null); 
                    result = -e;

                    }
                    break;
                case 7 :
                    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:37:4: IDENT
                    {
                    IDENT1=(CommonTree)match(input,IDENT,FOLLOW_IDENT_in_expression178); 

                    			if(variables.containsKey((IDENT1!=null?IDENT1.getText():null))){
                    				result = variables.get((IDENT1!=null?IDENT1.getText():null));
                    			}else{
                    				Random randomGenerator = new Random();
                    				result = randomGenerator.nextInt(10);
                    				variables.put((IDENT1!=null?IDENT1.getText():null), result);
                    			}
                    		

                    }
                    break;
                case 8 :
                    // /Users/mjf0303/Desktop/Android/NonAndroidMathRomp/src/calc/GrammarEvaluator.g:46:4: INTEGER
                    {
                    INTEGER2=(CommonTree)match(input,INTEGER,FOLLOW_INTEGER_in_expression185); 
                    result = Integer.parseInt((INTEGER2!=null?INTEGER2.getText():null));

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return result;
    }
    // $ANTLR end "expression"

    // Delegated rules


 

    public static final BitSet FOLLOW_expression_in_evaluator62 = new BitSet(new long[]{0x0000000000000000L});
    public static final BitSet FOLLOW_EOF_in_evaluator64 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_14_in_expression82 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expression_in_expression86 = new BitSet(new long[]{0x000000000007C070L});
    public static final BitSet FOLLOW_expression_in_expression90 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_15_in_expression99 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expression_in_expression103 = new BitSet(new long[]{0x000000000007C070L});
    public static final BitSet FOLLOW_expression_in_expression107 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_16_in_expression116 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expression_in_expression120 = new BitSet(new long[]{0x000000000007C070L});
    public static final BitSet FOLLOW_expression_in_expression124 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_17_in_expression133 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expression_in_expression137 = new BitSet(new long[]{0x000000000007C070L});
    public static final BitSet FOLLOW_expression_in_expression141 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_18_in_expression149 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expression_in_expression153 = new BitSet(new long[]{0x000000000007C070L});
    public static final BitSet FOLLOW_expression_in_expression157 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_NEGATION_in_expression166 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expression_in_expression170 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_IDENT_in_expression178 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INTEGER_in_expression185 = new BitSet(new long[]{0x0000000000000002L});

}